package com.waves.task.controller;

import com.waves.core.web.domain.R;
import com.waves.core.web.domain.TableDataInfo;
import com.waves.task.domain.dto.TaskCommentInsertDTO;
import com.waves.task.domain.dto.TaskCommentPageDTO;
import com.waves.task.domain.vo.TaskCommentPageVO;
import com.waves.task.service.TaskCommentService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;


@RestController
@RequestMapping("/taskComment")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@ApiModel("任务评论表对象功能接口")
public class TaskCommentController {

    private final TaskCommentService Service;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    @ApiResponses(@ApiResponse(code = 200, message = "success", response = TaskCommentPageVO.class))
    public TableDataInfo<TaskCommentPageVO> page(TaskCommentPageDTO dto) {
        return Service.pageTaskComment(dto);
    }


    @ApiOperation("新增")
    @PostMapping("/insert")
    @ApiResponses(@ApiResponse(code = 200, message = "success", response = Object.class))
    public R<Object> insert(@RequestBody TaskCommentInsertDTO insertDTO) {
        return R.ok(Service.insertTaskComment(insertDTO));
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    @ApiResponses(@ApiResponse(code = 200, message = "success", response = Object.class))
    public R<Object> delete(@RequestParam("taskCommentId") Long taskCommentId) {
        return R.ok(Service.deleteTaskComment(Collections.singletonList(taskCommentId)));
    }

    @ApiOperation(value = "点赞/取消赞")
    @GetMapping("/likeTask/{id}")
    public R<Object> likeTask(@PathVariable long id) {
        return R.ok(Service.likeTaskComment(id));
    }


}
